import axios from 'axios'
import {
  CHANGE_BANNER,
  CHANGE_RECOMMEND,
  FETCH_HOME_MULTIDATA
} from './constants'

const changeBannersAction = (banners) => ({
  type: CHANGE_BANNER,
  banners
})

const changeRecommendsAction = (recommends) => ({
  type: CHANGE_RECOMMEND,
  recommends
})

// thunk的action函数
const getHomeMultidataAction = () => {
  return (dispatch) => {
    axios.get('http://123.207.32.32:8000/home/multidata').then((res) => {
      const data = res.data.data
      dispatch(changeBannersAction(data.banner.list))
      dispatch(changeRecommendsAction(data.recommend.list))
    })
  }
}

export { changeBannersAction, changeRecommendsAction, getHomeMultidataAction }
